#pragma once

#include <algorithm>
#include <iostream>
#include <fstream>
#include <string>
#include <map>
using namespace std;

namespace uppg33
{
	class nils
	{
	private:
		map<string, int> counter;

		void readFile(string filename)
		{
			ifstream in(filename);
			string word;
			while (in >> word)
			{
				counter[word] += 1;
			}
		}

		static bool compare(const pair<string, int> a, const pair<string, int> b)
		{
			return a.second < b.second;
		}

	public:

		nils()
		{
			readFile("nils_holgersson.txt");
		}

		~nils()
		{
		}

		pair<string, int> getMostFrequentWord()
		{
			auto mfwIterator = max_element(counter.begin(), counter.end(), compare);
			return *mfwIterator;
		}
	};
}

